package com.sanpu.kxe.rxservice.client;

import android.support.v4.util.Pair;
import android.text.TextUtils;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.sanpu.kxe.business.main.bean.ActHomePopOutput;
import com.sanpu.kxe.business.main.bean.AdviceOutput;
import com.sanpu.kxe.business.main.bean.ApplyCardOutput;
import com.sanpu.kxe.business.main.bean.CertificationOldOutput;
import com.sanpu.kxe.business.main.bean.CertificationOutput;
import com.sanpu.kxe.business.main.bean.CheckVersionOutput;
import com.sanpu.kxe.business.main.bean.CreditEventOutput;
import com.sanpu.kxe.business.main.bean.EventCenterOutput;
import com.sanpu.kxe.business.main.bean.HomeBannerOutput;
import com.sanpu.kxe.business.main.bean.HomeCenterOutput;
import com.sanpu.kxe.business.main.bean.HomePageOutput;
import com.sanpu.kxe.business.main.bean.IntegralConvertOutput;
import com.sanpu.kxe.business.main.bean.InviteFriendsOutput;
import com.sanpu.kxe.business.main.bean.InviteMakeMoneyOutput;
import com.sanpu.kxe.business.main.bean.LinkfaceCheckOutput;
import com.sanpu.kxe.business.main.bean.MaterialPosterOutput;
import com.sanpu.kxe.business.main.bean.MaterialVideoOutput;
import com.sanpu.kxe.business.main.bean.MyProfitsOutput;
import com.sanpu.kxe.business.main.bean.NewsColumnsOutput;
import com.sanpu.kxe.business.main.bean.NewsContentOutput;
import com.sanpu.kxe.business.main.bean.NoticeOutput;
import com.sanpu.kxe.business.main.bean.PartnerAllyOutput;
import com.sanpu.kxe.business.main.bean.PartnerInfoOutput;
import com.sanpu.kxe.business.main.bean.PointDetailOutput;
import com.sanpu.kxe.business.main.bean.PointTotalOutput;
import com.sanpu.kxe.business.main.bean.PromotePosterOutput;
import com.sanpu.kxe.business.main.bean.PushDetailsOutput;
import com.sanpu.kxe.business.main.bean.PushMaterialOutput;
import com.sanpu.kxe.business.main.bean.RebateTotalOutput;
import com.sanpu.kxe.business.main.bean.ReferrerOutput;
import com.sanpu.kxe.business.main.bean.ShareNumOutput;
import com.sanpu.kxe.business.main.bean.UserCenterOutput;
import com.sanpu.kxe.business.main.bean.UserConfigOutput;
import com.sanpu.kxe.business.main.bean.UserSignOutput;
import com.sanpu.kxe.business.main.bean.WithdrawSignOutput;
import com.sanpu.kxe.business.main.bean.WxInfoOutput;
import com.sanpu.kxe.common.interfaces.CommonConfig;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.rxservice.BaseClient;
import com.sanpu.kxe.rxservice.MetaBean;
import com.sanpu.kxe.rxservice.RequestMap;
import com.sanpu.kxe.rxservice.interfaces.MainService;

import java.io.File;
import java.util.HashMap;
import java.util.List;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.functions.Func1;

/**
 * Description：main模块接口
 * Created by 薛勇军 on 2018/7/9.
 */

public class MainClient extends BaseClient {

    private static MainClient mInstance;

    public static MainClient getInstance() {
        if (mInstance == null) {
            synchronized (MainClient.class) {
                if (mInstance == null) {
                    mInstance = new MainClient();
                }
            }
        }
        return mInstance;
    }

    private MainService service;

    private MainClient() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(UrlConstants.getBaseUrl())
                .client(client)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        service = retrofit.create(MainService.class);
    }

    /**
     * 获取个人信息
     */
    public Observable<UserCenterOutput> userCenter() {
        return callMapAfterLogin(service.userCenter(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<UserCenterOutput>>() {
                    @Override
                    public Observable<UserCenterOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        UserCenterOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second, new TypeToken<UserCenterOutput>() {
                            }.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 获取个人配置信息
     */
    public Observable<UserConfigOutput> userConfig() {
        return callMapAfterLogin(service.userConfig(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<UserConfigOutput>>() {
                    @Override
                    public Observable<UserConfigOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        UserConfigOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second, new TypeToken<UserConfigOutput>() {
                            }.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 首页广告
     */
    public Observable<List<ActHomePopOutput>> actAppadlist() {
        return callMapAfterLogin(service.actAppadlist(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<ActHomePopOutput>>>() {
                    @Override
                    public Observable<List<ActHomePopOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<ActHomePopOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second, new TypeToken<List<ActHomePopOutput>>() {
                            }.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 获取推荐人的信息
     */
    public Observable<ReferrerOutput> getReferrerUserInfo() {
        return callMapAfterLogin(service.getReferrerUserInfo(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<ReferrerOutput>>() {
                    @Override
                    public Observable<ReferrerOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        ReferrerOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second, new TypeToken<ReferrerOutput>() {
                            }.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 修改昵称
     */
    public Observable<String> updateNickName(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.updateNickName(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 获取我的微信信息
     */
    public Observable<WxInfoOutput> getWxInfo() {
        return callMapAfterLogin(service.getWxInfo(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<WxInfoOutput>>() {
                    @Override
                    public Observable<WxInfoOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        WxInfoOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second, new TypeToken<WxInfoOutput>() {
                            }.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 上传我的微信信息
     */
    public Observable<String> postWxQrcode(JSONObject reqData, HashMap<String, File> files) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.postWxQrcode(requestMap.getReqParams(true), files2Parts(files)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 上传我的微信号
     */
    public Observable<String> postWxQrcode(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.postWxQrcode(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 上传活动中心
     */
    public Observable<List<EventCenterOutput>> getActInfList() {
        return callMapAfterLogin(service.getActInfList(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<EventCenterOutput>>>() {
                    @Override
                    public Observable<List<EventCenterOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<EventCenterOutput> output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<List<EventCenterOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 合伙人信息
     */
    public Observable<PartnerInfoOutput> partnerInf() {
        return callMapAfterLogin(service.partnerInf(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<PartnerInfoOutput>>() {
                    @Override
                    public Observable<PartnerInfoOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        PartnerInfoOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<PartnerInfoOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 合伙人盟友列表
     */
    public Observable<List<PartnerAllyOutput>> partnerAllyList(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.partnerAllyList(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<PartnerAllyOutput>>>() {
                    @Override
                    public Observable<List<PartnerAllyOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<PartnerAllyOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<PartnerAllyOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 获取认证信息
     */
    public Observable<CertificationOldOutput> getAuthInfo() {
        return callMapAfterLogin(service.getAuthInfo(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<CertificationOldOutput>>() {
                    @Override
                    public Observable<CertificationOldOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        CertificationOldOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<CertificationOldOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 四要素校验
     */
    public Observable<String> authentication(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.authentication(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 提交实名认证信息
     */
    public Observable<String> realNamePicAuth(JSONObject reqData, HashMap<String, File> files) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.realNamePicAuth(requestMap.getReqParams(true), files2Parts(files)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 上传身份证正反面
     */
    public Observable<CertificationOutput> uploadIdCardInfo(HashMap<String, File> files) {
        return callMapAfterLogin(service.uploadIdCardInfo(new RequestMap().getReqParams(true), files2Parts(files)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<CertificationOutput>>() {
                    @Override
                    public Observable<CertificationOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        CertificationOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<CertificationOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 上传银行卡正反面及手持
     */
    public Observable<CertificationOutput> uploadBankInfoAndFaceMatch(JSONObject reqData, HashMap<String, File> files) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.uploadBankInfoAndFaceMatch(requestMap.getReqParams(true), files2Parts(files)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<CertificationOutput>>() {
                    @Override
                    public Observable<CertificationOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        CertificationOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<CertificationOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 鉴权四要素加人脸识别
     */
    public Observable<String> realnameAuthentication(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.realnameAuthentication(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 鉴权四要素加人脸识别
     */
    public Observable<LinkfaceCheckOutput> auth(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.auth(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<LinkfaceCheckOutput>>() {
                    @Override
                    public Observable<LinkfaceCheckOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        LinkfaceCheckOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<LinkfaceCheckOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 实名认证（活体检测）
     */
    public Observable<String> liveness(JSONObject reqData, HashMap<String, File> files) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.liveness(requestMap.getReqParams(true), files2Parts(files)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 积分统计
     */
    public Observable<PointTotalOutput> pointTotal() {
        return callMapAfterLogin(service.pointTotal(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<PointTotalOutput>>() {
                    @Override
                    public Observable<PointTotalOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        PointTotalOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<PointTotalOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 积分明细列表
     */
    public Observable<List<PointDetailOutput>> pointDetailList(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.pointDetailList(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<PointDetailOutput>>>() {
                    @Override
                    public Observable<List<PointDetailOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<PointDetailOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<PointDetailOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 消息列表
     */
    public Observable<List<NoticeOutput>> messageList(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.messageList(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<NoticeOutput>>>() {
                    @Override
                    public Observable<List<NoticeOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<NoticeOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<NoticeOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 消息详情
     */
    public Observable<NoticeOutput> messageDetail(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.messageDetail(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<NoticeOutput>>() {
                    @Override
                    public Observable<NoticeOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        NoticeOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<NoticeOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 标记消息已读
     */
    public Observable<String> markMessageRead(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.markMessageRead(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 分享记录
     */
    public Observable<String> sharingIntegral(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.sharingIntegral(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 首页banner
     */
    public Observable<List<HomeBannerOutput>> banner() {
        return callMapAfterLogin(service.banner(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<HomeBannerOutput>>>() {
                    @Override
                    public Observable<List<HomeBannerOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<HomeBannerOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<HomeBannerOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 首页banner
     */
    public Observable<List<HomeBannerOutput>> newBanner() {
        return callMapAfterLogin(service.newBanner(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<HomeBannerOutput>>>() {
                    @Override
                    public Observable<List<HomeBannerOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<HomeBannerOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<HomeBannerOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 首页顶部功能栏
     */
    public Observable<List<HomePageOutput>> homePage() {
        return callMapAfterLogin(service.homePage(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<HomePageOutput>>>() {
                    @Override
                    public Observable<List<HomePageOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<HomePageOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<HomePageOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 首页中间功能栏
     */
    public Observable<List<HomeCenterOutput>> findHomeCenter() {
        return callMapAfterLogin(service.findHomeCenter(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<HomeCenterOutput>>>() {
                    @Override
                    public Observable<List<HomeCenterOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<HomeCenterOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<HomeCenterOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 办理信用卡
     */
    public Observable<List<ApplyCardOutput>> applyCard() {
        return callMapAfterLogin(service.applyCard(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<ApplyCardOutput>>>() {
                    @Override
                    public Observable<List<ApplyCardOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<ApplyCardOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<ApplyCardOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 今日签到
     */
    public Observable<UserSignOutput> userSign() {
        return callMapAfterLogin(service.userSign(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<UserSignOutput>>() {
                    @Override
                    public Observable<UserSignOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        UserSignOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<UserSignOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 卡积分兑换
     */
    public Observable<IntegralConvertOutput> integralConvert() {
        return callMapAfterLogin(service.integralConvert(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<IntegralConvertOutput>>() {
                    @Override
                    public Observable<IntegralConvertOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        IntegralConvertOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<IntegralConvertOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 佣金统计
     */
    public Observable<RebateTotalOutput> rebateTotal() {
        return callMapAfterLogin(service.rebateTotal(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<RebateTotalOutput>>() {
                    @Override
                    public Observable<RebateTotalOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        RebateTotalOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<RebateTotalOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 提现签约
     */
    public Observable<WithdrawSignOutput> withdrawSigning() {
        return callMapAfterLogin(service.withdrawSigning(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<WithdrawSignOutput>>() {
                    @Override
                    public Observable<WithdrawSignOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        WithdrawSignOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<WithdrawSignOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 我的团队列表（收益）
     */
    public Observable<MyProfitsOutput> myTeamList(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.myTeamList(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<MyProfitsOutput>>() {
                    @Override
                    public Observable<MyProfitsOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        MyProfitsOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<MyProfitsOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 推广海报朋友圈
     */
    public Observable<List<PromotePosterOutput>> getPosterList(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.getPosterList(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<PromotePosterOutput>>>() {
                    @Override
                    public Observable<List<PromotePosterOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<PromotePosterOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<PromotePosterOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 增加海报分享次数
     */
    public Observable<ShareNumOutput> addShareNum(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.addShareNum(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<ShareNumOutput>>() {
                    @Override
                    public Observable<ShareNumOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        ShareNumOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<ShareNumOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 地推物料列表（推广）
     */
    public Observable<List<PushMaterialOutput>> getMaterialList() {
        return callMapAfterLogin(service.getMaterialList(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<PushMaterialOutput>>>() {
                    @Override
                    public Observable<List<PushMaterialOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<PushMaterialOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<PushMaterialOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 物料详情列表
     */
    public Observable<List<PushDetailsOutput>> getMaterialDetailsList(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.getMaterialDetailsList(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<PushDetailsOutput>>>() {
                    @Override
                    public Observable<List<PushDetailsOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<PushDetailsOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<PushDetailsOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 获取新闻类型
     */
    public Observable<List<NewsColumnsOutput>> getNewsColumns() {
        return callMapAfterLogin(service.getNewsColumns(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<NewsColumnsOutput>>>() {
                    @Override
                    public Observable<List<NewsColumnsOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<NewsColumnsOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<NewsColumnsOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 获取新闻内容
     */
    public Observable<List<NewsContentOutput>> getNewsList(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.getNewsList(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<NewsContentOutput>>>() {
                    @Override
                    public Observable<List<NewsContentOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<NewsContentOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<NewsContentOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 记录点击新闻内容
     */
    public Observable<String> statisticalClick(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.statisticalClick(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 提交了难任务信息
     */
    public Observable<String> conmitTask(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.conmitTask(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 获取了难任务列表
     */
    public Observable<List<AdviceOutput>> getTaskList(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.getTaskList(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<AdviceOutput>>>() {
                    @Override
                    public Observable<List<AdviceOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<AdviceOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<AdviceOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 设置支付密码
     */
    public Observable<String> setPayPassword(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.setPayPassword(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 获取APP版本信息
     */
    public Observable<CheckVersionOutput> getAppVersionInfo(JSONObject reqData) {
        RequestMap requestMap = new RequestMap();
        requestMap.put(CommonConfig.REQDATA, new Gson().toJson(reqData));
        return callMapAfterLogin(service.getAppVersionInfo(requestMap.getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<CheckVersionOutput>>() {
                    @Override
                    public Observable<CheckVersionOutput> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        CheckVersionOutput output = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            output = new Gson().fromJson(pair.second,
                                    new TypeToken<CheckVersionOutput>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, output));
                    }
                });
    }

    /**
     * 信用卡活动
     */
    public Observable<List<CreditEventOutput>> creditcardActList() {
        return callMapAfterLogin(service.creditcardActList(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<CreditEventOutput>>>() {
                    @Override
                    public Observable<List<CreditEventOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<CreditEventOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<CreditEventOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 邀请好友
     */
    public Observable<List<InviteFriendsOutput>> inviteFriends() {
        return callMapAfterLogin(service.inviteFriends(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<InviteFriendsOutput>>>() {
                    @Override
                    public Observable<List<InviteFriendsOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<InviteFriendsOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<InviteFriendsOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 6.10.8邀请赚钱
     */
    public Observable<List<InviteMakeMoneyOutput>> inviteMakeMoney() {
        return callMapAfterLogin(service.inviteMakeMoney(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<InviteMakeMoneyOutput>>>() {
                    @Override
                    public Observable<List<InviteMakeMoneyOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<InviteMakeMoneyOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<InviteMakeMoneyOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 全部应用
     */
    public Observable<List<HomeCenterOutput>> findHomeCenterMore() {
        return callMapAfterLogin(service.findHomeCenterMore(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<HomeCenterOutput>>>() {
                    @Override
                    public Observable<List<HomeCenterOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<HomeCenterOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<HomeCenterOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 个人头像
     */
    public Observable<String> uploadUserHeadPortrait(HashMap<String, File> files) {
        return callMapAfterLogin(service.uploadUserHeadPortrait(new RequestMap().getReqParams(true), files2Parts(files)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<String>>() {
                    @Override
                    public Observable<String> call(Pair<MetaBean, String> pair) {
                        return toObservable(pair);
                    }
                });
    }

    /**
     * 6.10.10推广视频
     */
    public Observable<List<MaterialVideoOutput>> promotionVideo() {
        return callMapAfterLogin(service.promotionVideo(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<MaterialVideoOutput>>>() {
                    @Override
                    public Observable<List<MaterialVideoOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<MaterialVideoOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<MaterialVideoOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }

    /**
     * 6.10.9推广海报
     */
    public Observable<List<MaterialPosterOutput>> promotionPoster() {
        return callMapAfterLogin(service.promotionPoster(new RequestMap().getReqParams(true)))
                .flatMap(new Func1<Pair<MetaBean, String>, Observable<List<MaterialPosterOutput>>>() {
                    @Override
                    public Observable<List<MaterialPosterOutput>> call(Pair<MetaBean, String> pair) {
                        if (pair == null) {
                            return toObservable(null);
                        }
                        List<MaterialPosterOutput> outputs = null;
                        if (!TextUtils.isEmpty(pair.second)) {
                            outputs = new Gson().fromJson(pair.second,
                                    new TypeToken<List<MaterialPosterOutput>>() {}.getType());
                        }
                        return toObservable(new Pair<>(pair.first, outputs));
                    }
                });
    }
}
